#include "logger.h"
#include "../Globals/globals.h"
#include <stdio.h>

char *KEYS[NUM_OF_STAT_KEYS] = {
	"Input audio bytes that were lost because of slow reading from input",
	"Encoded audio bytes that were lost because of slow encoding"
};

FILE* outputFile;
DEBUG_LEVEL debugLevel;
BOOL initialized;
int keyValues[NUM_OF_STAT_KEYS];

void initializeLogger(FILE* output, DEBUG_LEVEL level)
{
	if (initialized != FALSE)
		return;
	initialized = TRUE;
	outputFile = output;
	debugLevel = level;
}

void startLogger()
{
	if (initialized == FALSE)
		return;
}

void addToCount(STATS_KEY key, int delta)
{
	keyValues[key]+=delta;
}

void logString(DEBUG_LEVEL level, char* msg)
{
	if (initialized == FALSE)
		return;
	if (level >= debugLevel)
		fprintf(outputFile,"%s\n",msg);
}

void outputStats()
{
	int key;
	
	for (key=0;key<NUM_OF_STAT_KEYS;++key)
	{
		fprintf(outputFile,"%s=%d\n",KEYS[key],keyValues[key]);
	}
}

void stopLogger()
{
	if (initialized == FALSE)
		return;
}

void destroyLogger()
{
	if (initialized == FALSE)
		return;
	initialized = FALSE;
}
